﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using VanTaiBLL;
using VanTaiData;
using VanTaiProperty;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using Roles;

namespace VanTaiTMS.Page
{
    public partial class nhat_ky_dieu_dong : System.Web.UI.Page
    {
        #region[Define]
        private DataTable dtLog;
        private DataTable dtSearch;
        private DataTable dtFilter;
        private DataTable dtAutoComplete;
        protected string SuggestionList;
        protected string StrAlert = string.Empty;
        protected clsBusiness_TMCommandTransferOrder clsLog = new clsBusiness_TMCommandTransferOrder();
        #endregion

        #region[Controler]
        protected void Page_Load(object sender, EventArgs e)
        {
            Autocomplate();
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        protected void cmdSerach_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "")
            {
                StrAlert += "<div class='alert alert-warning'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Vui lòng nhập vào từ khoá để tìm kiếm !";
                StrAlert += "</div>";
            }
            else
            {
                Search(txtSearch.Text);
            }
        }
        protected void cmdRefesh_Click(object sender, EventArgs e)
        {
            txtSearch.Text = "";
            txtTuNgayNgayNhapKho.Text = "";
            txtDenNgayNhapKho.Text = "";
            BindGrid();
        }
        protected void cmdFilter_Click(object sender, EventArgs e)
        {
 
        }
        //----------------pagger------------------------
        protected void DataPagerListAll_PreRender(object sender, EventArgs e)
        {
            BindGrid();
        }
        //-------------list-view-----------------------
        protected void ListViewAll_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
                
        }
        protected void ListViewAll_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LinkButton linkListName = (LinkButton)e.Item.FindControl("linkListName");
                LinkButton link_stt = (LinkButton)e.Item.FindControl("link_stt");
                string _jsDouble1 = ClientScript.GetPostBackClientHyperlink(linkListName, "");

                linkListName.Attributes["ondblclick"] = _jsDouble1;
                linkListName.Attributes["onclick"] = "return false;";

                if (link_stt.Text == "1")
                {
                    link_stt.Text = "Đã hoàn tất";
                }
            }
        }
        #endregion

        #region[Function]
        protected void BindGrid()
        {
            dtLog = clsLog.BindGridTM_Log(txtSearch.Text);
            if (dtLog != null && dtLog.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtLog;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;
            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
            }
        }
        protected void Autocomplate()
        {
            dtAutoComplete = clsLog.BindGridTM_Log(string.Empty);
            if (dtAutoComplete != null && dtAutoComplete.Rows.Count > 0)
            {
                foreach (DataRow dr in dtAutoComplete.Rows)
                {
                    if (string.IsNullOrEmpty(SuggestionList))
                    {
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Vehicle_Number"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["DommandTransferOrder_Alias"].ToString().Replace("\n", " ") + "\",";
                    }
                    else
                    {
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Vehicle_Number"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["DommandTransferOrder_Alias"].ToString().Replace("\n", " ") + "\",";
                    }
                }
            }
        }
        protected void Search(string keywords)
        {
            dtSearch = clsLog.BindGridTM_Log(keywords);
            if (dtSearch != null && dtSearch.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtSearch;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

                StrAlert += "<div class='alert alert-success'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Tìm thấy " + dtSearch.Rows.Count.ToString() + " mẫu tin !";
                StrAlert += "</div>";
            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
                StrAlert += "<div class='alert alert-error'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Không tìm thấy mẫu tin nào !";
                StrAlert += "</div>";
            }
        }
        protected void Fillter(string DateBegin, string EndBegin)
        {
            dtFilter = clsLog.TMCommandTransferOrde_Fillter_Date(txtTuNgayNgayNhapKho.Text, txtDenNgayNhapKho.Text);
            if (dtFilter != null && dtFilter.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtFilter;
                ListViewAll.DataBind();

                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

                StrAlert += "<div class='alert alert-success'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Tìm thấy " + dtFilter.Rows.Count.ToString() + " mẫu tin !";
                StrAlert += "</div>";
            }
            else
            {
                StrAlert += "<div class='alert alert-error'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Không tìm thấy mẫu tin nào !";
                StrAlert += "</div>";
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
            }
        }
        #endregion
    }
}